$(function(){
	showCondition(true);
	var param = drgUI.setAjaxData(tabId);
	// 标题
	$("#"+ tabId + " #header").html(param.desc) ;
	var sliderVal = param.sliderVal ;
	if(param.intervel == 1) {
		$("#"+ tabId + " #moduleTitle").html("<i class='fa fa-pie-chart' aria-hidden='true'></i>超标"+sliderVal+"%及以上病例区间内科室费用构成及对比") ;
	}  else if(param.intervel == 2) {
		$("#"+ tabId + " #moduleTitle").html("<i class='fa fa-pie-chart' aria-hidden='true'></i>超标"+sliderVal+"%及以内病例区间内科室费用构成及对比") ;
	} else if(param.intervel == 3) {
		$("#"+ tabId + " #moduleTitle").html("<i class='fa fa-pie-chart' aria-hidden='true'></i>未超标病例区间内科室费用构成及对比") ;
	} 
	param.pType = "1" ;
	param.sliderVal = (100+Number(param.sliderVal))/100;
	$.post(contextPath + "/payGroup/queryOverCaseFee.dhc",param).done(function(data) {
		var data = data.data ;
		// 区间内病例科室分布
		// 费用区间内病例科室分布图
		var caseDis = []; // 病例分布
		for(var o in data) {
			caseDis.push({name:data[o].DEP_NAME,value:data[o].CNT});
		}
		var echartConfig = {pagemode:true,"showLabel":false,"showLabelLine":true,radius:[0,'60%'],legendItemGap:5}
		pieCharts($("#"+tabId+" #caseDepDis"), caseDis, '费用区间内病例科室分布图', "超标"+paramTabPage[tabId].sliderVal+"%及以上病例",echartConfig);
		// 病例区间分布表
		var columns=[
		               	{"data": "DEP_NAME","title":"科室"},
		               	{"data": "CNT","title":"病例数", 
		               		"render": function(obj, type, full,meta) {
		               			if(full.CNT>0){
			               			return "<a depcode = '"+full.DEP_CODE+"' class=\"cnt\">"+full.CNT+"</a>" ;
			               		}
		               			return full.CNT;
		           			}
		               	},
		               	{"data": "CNTR","title":"病例数占比(%)" ,
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.CNTR,2);
		           			}
		               	},
		               	{"data": "AVGFEE","title":"次均费用" ,
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.AVGFEE,2);
		           			}
		               	},
		           		{"data": "AVGFEESTD","title":"次均费用标杆",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.AVGFEESTD,2);
		           			}
		               	},
		           		{"data": "OVERFEE","title":"病例累计超标费用(万元)"}
		           	];
		var paramsDataTables={ordering:false,stateSave:true,columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
		$("#"+tabId+" #caseIntervelDisTab").dataTableBasic(columns,data,paramsDataTables) ;
		$("#"+tabId+" #caseIntervelDisTab_wrapper caption").html("<h5>" + "病例区间分布表"+"</h5>") ;
		$("#"+tabId+" #caseIntervelDisTab tbody td").on("click",".cnt",function() {
			var param = drgUI.setAjaxData(tabId);
			param.pType = "1" ;
			param.depCode = $(this).attr("depcode");
			param.sliderVal = sliderVal;
//			param.methodType = "1";
			openTab('/pages/paygroup/paygroup_drgscaselist.jsp', param.pardrgCode + "|病例明细", "paygroup_drgscaselist" , "paygroup_drgscaselist", param);
		})
		
		// 图例边距和名称
		var legend = {"x":"40%","y":50, "data": ["次均费用"] } ;
		// 科室次均费用对比图
		var paramEch = {"title":"科室次均费用对比图","subtitle":paramTabPage[tabId].desc,"legend":legend,"series":[{"data":[],"name":"次均费用"}],"y":{"data":[],"name":"次均费用"}};
		for(var o in data) {
			paramEch.series[0].data.push(data[o].AVGFEE) ;
			paramEch.y.data.push(data[o].DEP_NAME) ;
		} ;
		paramEch.gridTop = '80' ;
		// 病组费用对比
		drawPayGroupBarChart("avgFeeForm",paramEch) ;
		
		// 科室次均费用构成及对比图
		var legend = {"x":50,"y":50, "data": ['医疗费用', '护理费用','管理费用','医技费用','药品耗材费用'] } ;
		var paramEchR = {"title":"科室费用构成及对比图","subtitle":paramTabPage[tabId].desc,"legend":legend,"series":[
		                                                              {"name":"医疗费用","type":"bar","data":[]},
		                                                              {"name":"护理费用","type":"bar","data":[]},
		                                                              {"name":"管理费用","type":"bar","data":[]},
		                                                              {"name":"医技费用","type":"bar","data":[]},
		                                                              {"name":"药品耗材费用","type":"bar","data":[]}
		                                                              ],"y":{"data":[]}};
		for(var o in data) {
			paramEchR.series[0].data.push(data[o].MEDFEE) ;
			paramEchR.series[1].data.push(data[o].NURSFEE) ;
			paramEchR.series[2].data.push(data[o].MANAGEFEE) ;
			paramEchR.series[3].data.push(data[o].TECHFEE) ;
			paramEchR.series[4].data.push(data[o].DRUGMATERFEE) ;
			paramEchR.y.data.push(data[o].DEP_NAME) ;
		} ;
		paramEchR.gridTop = '80' ;
		// 病组费用构成
		drawPayGroupBarChart("feeForm",paramEchR,null,"stackbar") ;
		
		// 绘制表格
		var columns=[
		               	{"data": "DEP_NAME","title":"科室"},
		               	{"data": "CNT","title":"病例数" ,
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.CNT,0);
		           			}
		                },
		               	{"data": "CNTR","title":"病例数占比(%)" ,
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.CNTR,2);
		           			}
		           		},
		               	{"data": "AVGFEE","title":"次均费用" ,
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.AVGFEE,2);
		           			}
		           		},
		           		{"data": "DRUGCOST","title":"药品费用",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.DRUGCOST,2);
		           			}
		           		},
		           		{"data": "DRUGRATIO","title":"药占比(%)",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.DRUGRATIO,2);
		           			}},
		           		{"data": "AVGDAYS","title":"平均住院日",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.AVGDAYS,2);
		           			}
		           		},
		           		{"data": "MEDFEE","title":"医疗费用",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.MEDFEE,2);
		           			}
		           		},
		           		{"data": "NURSFEE","title":"护理费用",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.NURSFEE,2);
		           			}
		           		},
		           		{"data": "MANAGEFEE","title":"管理费用",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.MANAGEFEE,2);
		           			}
		           		},
		           		{"data": "TECHFEE","title":"医技费用",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.TECHFEE,2);
		           			}
		           		},
		           		{"data": "DRUGMATERFEE","title":"药品耗材费用",
		               		"render": function(obj, type, full) {
		               			return formatNumPayGroup(full.DRUGMATERFEE,2);
		           			}
		           		} ,
		           		{"data": "operation","title":"操作",
		           			"render": function(obj, type, full,meta) {
		           				return "<a data-rowindex='"+meta.row+"'>费用构成</a>" ;
		           			}
		           		}
	  ];
		var paramsDataTables={ordering:false,stateSave:true,tableTitle:param.pardrgCode + "病组内费用超标"+sliderVal+"%及以上病例科室次均费用、费用构成及对比情况表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
		var table = $("#"+tabId+" #feeFormTab").dataTableBasic(columns,data,paramsDataTables) ;
		$("#"+tabId+" #feeFormTab_wrapper caption").html("<h5>"+param.pardrgCode + "病组内费用超标"+sliderVal+"%及以上病例科室次均费用、费用构成及对比情况表"+"</h5>") ;
		$("#"+tabId+" #feeFormTab tbody td").on("click","a",function(){
			var index = $(this).attr("data-rowindex");
	    	var a = table.row( index ).data();//本期|同期|上期
	    	var b = paramTabPage[tabId].target;//标杆
	    	var c = ["desc","MEDFEE","NURSFEE","MANAGEFEE","TECHFEE","DRUGMATERFEE","AVGFEE"];
	    	a.desc = "本期值";
	    	costStructure(a,b,c);
		})
	})

}) 
